package com.mdd.admin.controller.client;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IClientCrmFileService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.ClientCrmFileCreateValidate;
import com.mdd.admin.validate.ClientCrmFileUpdateValidate;
import com.mdd.admin.validate.ClientCrmFileSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.ClientCrmFileListedVo;
import com.mdd.admin.vo.ClientCrmFileDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/file")
@Api(tags = "客户文件管理")
public class ClientCrmFileController {

    @Resource
    IClientCrmFileService iClientCrmFileService;

    @GetMapping("/list")
    @ApiOperation(value="客户文件列表")
    public AjaxResult<PageResult<ClientCrmFileListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated ClientCrmFileSearchValidate searchValidate) {
        PageResult<ClientCrmFileListedVo> list = iClientCrmFileService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="客户文件详情")
    public AjaxResult<ClientCrmFileDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        ClientCrmFileDetailVo detail = iClientCrmFileService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "客户文件新增")
    @PostMapping("/add")
    @ApiOperation(value="客户文件新增")
    public AjaxResult<Object> add(@Validated @RequestBody ClientCrmFileCreateValidate createValidate) {
        iClientCrmFileService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "客户文件编辑")
    @PostMapping("/edit")
    @ApiOperation(value="客户文件编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody ClientCrmFileUpdateValidate updateValidate) {
        iClientCrmFileService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "客户文件删除")
    @PostMapping("/del")
    @ApiOperation(value="客户文件删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iClientCrmFileService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
